﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Drawing;
using System.Windows.Forms;

namespace Presentation
{
	public enum ToolStripBorderType
	{
		Top,
		Bottom,
        None
	}

    public class CustomToolStripSystemRenderer : ToolStripSystemRenderer
    {
		private Brush brush;
		private ToolStripBorderType borderType;

		public Brush Brush
		{
			get { return brush; }
			set { brush = value; }
		}

		public ToolStripBorderType BorderType
		{
			get { return borderType; }
			set { borderType = value; }
		}

		public CustomToolStripSystemRenderer(ToolStripBorderType border)
		{
			brush = Brushes.DarkGray;
			borderType = border;
		}

		public CustomToolStripSystemRenderer(ToolStripBorderType border, Brush b)
		{
			brush = b;
			borderType = border;
		}

		protected override void OnRenderToolStripBackground(ToolStripRenderEventArgs e)
		{
			if (borderType == ToolStripBorderType.Bottom)
			{
				ToolStripProfessionalRenderer b = new ToolStripProfessionalRenderer();
				b.DrawToolStripBackground(e);
			}
			//base.OnRenderToolStripBackgound(e);
		}

        protected override void OnRenderToolStripBorder(ToolStripRenderEventArgs e)
        {
			Rectangle imageRectangle = new Rectangle(
			1,
			1,
			e.ToolStrip.Width - 2,
			e.ToolStrip.Height - 2);

			Rectangle border = new Rectangle();

			switch (borderType)
			{
				case ToolStripBorderType.Top:
					border = new Rectangle(0, 0, e.ToolStrip.Width, 1);
                    e.Graphics.FillRectangle(brush, border);
					break;
				case ToolStripBorderType.Bottom:
					border = new Rectangle(0, imageRectangle.Bottom, e.ToolStrip.Width, e.ToolStrip.Bounds.Bottom - imageRectangle.Bottom);
                    e.Graphics.FillRectangle(brush, border);
                    break;
			}
            //base.OnRenderToolStripBorder(e);
        }

		protected override void OnRenderSeparator(ToolStripSeparatorRenderEventArgs e)
		{
			ToolStripProfessionalRenderer b = new ToolStripProfessionalRenderer();
			b.DrawSeparator(e);
			//base.OnRenderSeparator(e);
		}
    }
}
